package com.nfc.lock.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nfc.lock.common.result.Result;
import com.nfc.lock.entity.OperationLog;
import com.nfc.lock.service.IOperationLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 操作日志Controller
 */
@Tag(name = "操作日志")
@RestController
@RequestMapping("/api/v1/log")
@RequiredArgsConstructor
public class OperationLogController {

    private final IOperationLogService operationLogService;

    @Operation(summary = "分页查询操作日志")
    @GetMapping("/list")
    public Result<IPage<OperationLog>> getLogList(
            @Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer pageSize,
            @Parameter(description = "操作类型") @RequestParam(required = false) Integer operationType,
            @Parameter(description = "操作用户ID") @RequestParam(required = false) Long userId,
            @Parameter(description = "锁具NFC ID") @RequestParam(required = false) String lockNfcId,
            @Parameter(description = "开始时间") @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
            @Parameter(description = "结束时间") @RequestParam(required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime
    ) {
        return Result.success(operationLogService.getLogList(pageNum, pageSize, operationType,
                userId, lockNfcId, startTime, endTime));
    }
}
